package aps

import glory.xxd.Utils
import org.json.JSONObject

class UnloadEQPMeterialController {

    def commentService

    /**
     "<Request>
     <Header>
     <MESSAGENAME>UnloadEQPMeterial</MESSAGENAME>
     <TRANSACTIONID>3916c0f2-50be-4dfe-afef-6c020d876503</TRANSACTIONID>
     <USERNAME>EAP</USERNAME>
     </Header>
     <Body>
     <EqpId>1FS04</EqpId>
     <OPID>180</OPID>
     <Materials>
         <MesMaterial>
             <MaterialPartNo>ZH05-SD3000-N1-50 BB</MaterialPartNo>
             <Type>WaferSaw</Type>
             <SeqNo>H180209KP401</SeqNo>
         </MesMaterial>
     </Materials>
     </Body>
     </Request>"
     * @return
     */
    def index() {
        def EqpId = params.EqpId ?: ""
        def OPID = params.OPID?:""
        def MaterialPartNo = params.MaterialPartNo?:""
        def Type = params.Type?:""
        def SeqNo = params.SeqNo?:""
        def USERNAME = params.USERNAME ?: ""


        def body =JSONObject.newInstance()
        body.put("EqpId",EqpId)
        body.put("OPID",OPID)

        def mm1 = JSONObject.newInstance()
        mm1.put("MaterialPartNo",MaterialPartNo)
        mm1.put("Type",Type)
        mm1.put("SeqNo",SeqNo)

        def mm2 = new JSONObject()
        mm2.put("MesMaterial",mm1)

        body.put("Materials", mm2)

        String logUUID = Utils.getUUID();

        def header = JSONObject.newInstance()
        header.put("MESSAGENAME","UnloadEQPMeterial")
        header.put("TRANSACTIONID",logUUID)
        header.put("USERNAME",USERNAME)



        def jsonAll =  [Header:header,Body:body]//JSONObject.newInstance()
        //jsonAll.put("Body",body)
        //jsonAll.put("Header",header)


        def jsonRequest = JSONObject.newInstance()
        jsonRequest.put("Request",jsonAll)

         //println jsonAll
        def json = commentService.getJsonByJsonForTopic2Queue(logUUID, jsonRequest)

        render json
    }
}
